package fun.codefarmer.pm.controller.management.hr;

import fun.codefarmer.pm.dto.HrDto;
import fun.codefarmer.pm.mapper.HrMapper;
import fun.codefarmer.pm.model.Hr;
import fun.codefarmer.pm.model.RespBean;
import fun.codefarmer.pm.model.Role;
import fun.codefarmer.pm.service.HrService;
import fun.codefarmer.pm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 操作员管理
 *
 * @ @ClassName HrController
 * @ Descriotion TODO
 * @ Author admin
 * @ Date 2022/04/28 22:19
 **/
@RestController
@RequestMapping("/system/hr")
public class HrController {
    @Autowired
    private HrService hrService;
    @Autowired
    private RoleService roleService;



    /**
     * 操作员管理页面，查询所有人员，不是员工，是hr
     *
     * @return
     */
    @GetMapping("/")
    public List<Hr> getAll(String name) {
        return hrService.getAll(name);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public RespBean deleteHrRole(@PathVariable Integer id) {
        // 删除hr  同时要删除对应的角色
        return hrService.deleteHrRole(id);
    }

    /**
     * 修改
     *
     * @param hr
     * @return
     */
    @PutMapping("/")
    public RespBean updateHr(@RequestBody Hr hr) {
        return hrService.updateHr(hr);
    }

    /**
     * 根据hrid 查询hr 详情
     * @param hr
     * @return
     */
    @PostMapping("/getHrById")
    public RespBean getHrById(@RequestBody Hr hr) {
        HrDto hrone = hrService.getHrById(hr);
        return RespBean.ok("查询成功", hrone);
    }

    /**
     * 修改 操作员
     * @param hr
     * @return
     */
    @PostMapping("/update")
    public RespBean updateHrByid(@RequestBody HrDto hr) {
        return hrService.updateHrByid(hr);
    }

    /**
     * 新增操作员
     * @param hr
     * @return
     */
    @PostMapping("/save")
    public RespBean save(@RequestBody HrDto hr) {
        return hrService.save(hr);
    }

    /**
     * 操作员全部角色
     * @return
     */
    @GetMapping("/role")
    public List<Role> getAllRole() {
        return roleService.getAllRole();
    }
}
